package com.br.framework.util.web;

import org.springframework.beans.BeansException;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;

public class ContextHolder implements ApplicationContextAware{
	
	private static ApplicationContext appCtx;
	
	public ContextHolder(){}

	@Override
	public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
		appCtx = applicationContext;
	}
	
	public static ApplicationContext getContext(){
		return appCtx;
	}
	
	/**
	 * 빈 이름으로 가지고 오기 
	 * @param beanName
	 * @return
	 */
	public static Object getBean(String beanName){
		return ContextHolder.getContext().getBean(beanName);
	}
	
	/**
	 * Bean 클래스 이름으로 가지고 오기 
	 * @param classObj
	 * @return
	 */
	@SuppressWarnings("unchecked")
	public static Object getBean(Class classObj){
		return ContextHolder.getContext().getBean(classObj);
	}
	
	
	
}
